package cn.sunlelin.educationserver.service.Impl;

import cn.sunlelin.educationserver.entity.Fathertype;
import cn.sunlelin.educationserver.mapper.FathertypeMapper;
import cn.sunlelin.educationserver.service.FathertypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class FathertypeServiceImpl implements FathertypeService {
    @Autowired
    FathertypeMapper fathertypeMapper;

    @Override
    public Boolean createFathertype(Fathertype fathertype) {
        if(this.selectFathertypeByName(fathertype.getFathertypeName())!=null)
            return false;
        fathertype.setCreateTime(new Date());
        fathertypeMapper.createFathertype(fathertype);
        return true;
    }

    @Override
    public Boolean updateFathertype(Fathertype fathertype) {
        Fathertype t=this.selectFathertypeById(fathertype.getFathertypeId());
        if(t==null)
            return false;
        if(!t.getFathertypeName().equals(fathertype.getFathertypeName())&&this.selectFathertypeByName(fathertype.getFathertypeName())!=null)
            return false;
        fathertype.setUpdateTime(new Date());
        fathertypeMapper.updateFathertype(fathertype);
        return true;
    }

    @Override
    public List<Fathertype> findAll() {
        return fathertypeMapper.findAll();
    }

    @Override
    public Fathertype selectFathertypeById(Integer fathertypeId) {
        return fathertypeMapper.selectFathertypeById(fathertypeId);
    }

    @Override
    public Fathertype selectFathertypeByName(String fathertypeName) {
        return fathertypeMapper.selectFathertypeByName(fathertypeName);
    }

    @Override
    public Boolean deleteFathertype(Integer fathertypeId) {
        if(this.selectFathertypeById(fathertypeId)==null)
            return false;
        Fathertype fathertype=new Fathertype();
        fathertype.setFathertypeId(fathertypeId);
        fathertype.setUpdateTime(new Date());
        fathertypeMapper.deleteFathertype(fathertype);
        return true;
    }
}
